package com.xykj.enterprise.wechat.ext.api.contacts.tag;

import com.xykj.enterprise.wechat.ext.service.contacts.ContactsTagService;
import com.xykj.enterprise.wechat.bean.ext.contacts.tag.GetTagUserVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Function(description = "获取标签成员", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "access_token", required = true),

        @Parameter(name = "tagid", type = Type.Integer, description = "标签id，非负整型，指定此参数时新增的标签会生成对应的标签id，不指定时则以目前最大的id自增。", required = true),
})
@Component
public class GetTagUser implements Action {

    @Autowired
    private ContactsTagService contactsTagService;

    @Override
    public Response execute(Request request) throws Exception {
        Integer tagid = request.getInteger("tagid");
        GetTagUserVo rsp = contactsTagService.getTagUser(
                request.getString("access_token"), tagid
        );
        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success().put("data", rsp);
    }
}
